package com.aircoinst.orderservice;

import com.aircoinst.feign.client.UserClient;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableFeignClients(clients = UserClient.class) //开启Feign自动装配
public class OrderServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(OrderServiceApplication.class, args);
    }

    /**
     * 配置RestTemplate并注入到容器 提供feign远程调用使用
     */
    @Bean
    @LoadBalanced // 启用负载均衡策略
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }

    /**
     * 配置负载均衡[全局模式]
     * 负载均衡的机制为[轮询机制]
     */
    @Bean
    public IRule randomRule() {
        return new RandomRule();
    }
}
